//
// Created by Administrator on 2023/7/30.
//
#include <iostream>
#include <cstdint>

using namespace std;

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int count = 0;
        while (n){
            count += n & 1;
            n >>= 1;
        }
        return count;
    }
};
class Solution2 {
public:
    int hammingWeight(uint32_t n) {
        int ret = 0;
        while (n) {
            // 将最小的一位1变成0
            n &= n - 1;
            ret++;
        }
        return ret;
    }
};

int main() {
    Solution2 s;
    cout << s.hammingWeight(00000000000000000000000000001011) << endl;
    cout << s.hammingWeight(00000000000000000000000010000000) << endl;
}
